/******************************************************************************
 * Copyright (C) 2017 ShenZhen ComTop Information Technology Co.,Ltd
 * All Rights Reserved.
 * 本软件为深圳康拓普开发研制。未经本公司正式书面同意，其他任何个人、团体不得使用、
 * 复制、修改或发布本软件.
 ******************************************************************************/
package com.comtop.springboot.templet.common.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Component;

/**
 * mybatisplus自定义填充公共字段 ,即没有传的字段自动填充
 *
 * @author wangjiafang
 * @version 1.0
 * @since 2017-10-12 wangjiafang
 */
@Component
public class MyMetaObjectHandler  extends MetaObjectHandler {
    //新增填充
    @Override
    public void insertFill(MetaObject metaObject){
      /*  Object userId = metaObject.getValue("userId");
        //获取当前登录用户
        Object principal = SecurityUtils.getSubject().getPrincipal();
        //直接强转SysUserEntity失败，通过json方式获取用户id
        String json = JSON.toJSONString(principal);
        JSONObject jsonObject = JSON.parseObject(json);
        Long currUserId = jsonObject.getLong("userId");
        if (null == userId) {
            metaObject.setValue("userId", currUserId);
        }*/
    }

    //更新填充
    @Override
    public void updateFill(MetaObject metaObject) {
        //insertFill(metaObject);
    }
}
